package com.bop.dehong.webview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;

import com.base.dehong.util.ToastUtils;
import com.bop.dehong.base.DeHongApp;
import com.bop.dehong.center.RechargeActivity;
import com.bop.dehong.config.Config;
import com.bop.dehong.decaifu.ToubiaoTyjActivity;
import com.bop.dehong.login.RegisterActivity;
import com.bop.dehong.main.MainActivity;

/**
 *WebView与JS的交互类
 * @author Tangwenhan
 *2015-11-16下午3:10:36
 */
public class JavaScriptObject {
	private Activity mContext;
	public JavaScriptObject(Activity context) {
		super();
		mContext = context;
	}
	@JavascriptInterface
	public void setTitle(String title){
		((WebViewActivity)mContext).setTitle(title);
	}
	@JavascriptInterface
	public void go2Recharge(){
		if (DeHongApp.mLoginEntity != null ) {
			if ("2".equals(DeHongApp.mUserInfo.certification)) {
				Intent reIntent = new Intent(mContext,RechargeActivity.class);//充值
				mContext.startActivityForResult(reIntent, WebViewActivity.RESULT_FOR_RECHARGE);
			}else{
				ToastUtils.show(mContext, "当前用户未认证，不能充值！");
			}
		}else {
			ToastUtils.show(mContext, "当前用户未登录！");
		}
	}
	@JavascriptInterface
	public void go2Register(){
		Intent intent = new Intent(mContext, RegisterActivity.class);
		mContext.startActivity(intent);
	}
	@JavascriptInterface
    public void go2Loan(){
		if (!TextUtils.isEmpty(Config.GOBID)) {
			Intent intent = new Intent(mContext,ToubiaoTyjActivity.class);//投标
			Bundle bundle = new Bundle();
			bundle.putString(Config.CAT_ID, Config.GOBID);
			intent.putExtras(bundle);
			mContext.startActivity(intent);
		}else {
			Intent intent = new Intent(mContext,MainActivity.class);//投标
			intent.putExtra("page", 1);
			mContext.startActivity(intent);
		}
    }

}

